<?php
/**
 * 汽车类别逻辑类
 * @author zengnz
 *
 */

class CarCategoryLogic
{
	// 缓存模型类
	private $_CacheModel = '';
	// 所有汽车品牌类别
	const ALL_BRANDS = 'ALL_CAR_BRANDS';
	// 所有汽车子类别
	const SUB_BRANDS = 'SUB_CAR_BRANDS';
	// 所有汽车品牌
	const ALL_CATEGORYS = 'ALL_CAR_CATEGORYS';
	
	public function __construct() {
		$this -> _CacheModel = D('Cache', 'Service');
		$this -> _CacheModel -> init();
	}
	
	// 获取汽车车型类别
	public function getCarTypes() {
		return CarCategoryModel::$carTypes;		
	}
	
	// 获取汽车国别类别
	public function getCarCountryTypes() {
		return CarCategoryModel::$carCountryTypes;
	}
	
	/**
	 * 获取汽车品牌列表
	 * return array 品牌信息
	 */
	public function getCarBrands() {
		$key = self::ALL_BRANDS;
	
		$brands = $this -> _CacheModel -> get($key);
		if (!$brands) {
			$brands = D('CarBrand') -> select();
				
			$this -> _CacheModel -> set($key, $brands);
			$this -> _CacheModel -> saveKeys($key, 'init');
		}
	
		return $brands;
	}
	
	/**
	 * 获取子类别
	 */
	public function getSubBrands() {
		$key = self::SUB_BRANDS;
	
		$brands = $this -> _CacheModel -> get($key);
		if (!$brands) {
			$brands = D('CarBrand') -> where('pid != 0') -> select();
	
			$this -> _CacheModel -> set($key, $brands);
			$this -> _CacheModel -> saveKeys($key, 'init');
		}
	
		return $brands;
	}
	
	
	/**
	 * 获取汽车车型
	 *
	 */
	public function getCarCategorys() {
		$key = self::ALL_CATEGORYS;
	
		$categorys = $this -> _CacheModel -> get($key);
		if (!$categorys) {
			$categorys = D('CarCategory') -> select();
				
			$this -> _CacheModel -> set($key, $categorys);
			$this -> _CacheModel -> saveKeys($key, 'init');
		}
			
		return $categorys;
	}
	
}